package domain;

import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.util.Date;

public abstract class Transaction {
    private Account account;
    private String transType;
    private String curBalance;
    private String amount;
    private String dateTime;
    private String seiralNumber;

    public static final DecimalFormat decimalFormat = new DecimalFormat("0.00");


    protected Transaction(Account account) {
        this(account,null);
        this.dateTime = new Date().toString();
    }

    protected Transaction(Account account,String transType){
        this.account = account;
        this.curBalance = (account != null)?(this.curBalance = account.getBalance().getBalance()):(null);
        this.transType = transType;
        this.dateTime =  LocalDateTime.now().toString();
    }

    public void endTransaction(){

    }
    @Override
    public String toString(){
        StringBuffer receiptText = new StringBuffer("\u81ea\u52a8\u67dc\u5458\u673a\u5ba2\u6237\u51ed\u5355");//自动柜员机客户凭单
        receiptText.append("\n" +
                "\u6237\u540d:" + account.getCustomer().getName());//户名
        receiptText.append("\n" +
                "\u5361\u53f7:" + account.getCard().getCardNumber());//卡号
        receiptText.append("\n" +
                "ATM\u7f16\u53f7:" + ATM.DEVICE_NUMBER);//ATM编号
        receiptText.append("\n" +
                "\u4ea4\u6613\u65e5\u671f\u53ca\u65f6\u95f4:\n"
                + dateTime);//交易日期及时间
        receiptText.append("\n" +
                "\u4ea4\u6613\u91d1\u989d:" + account.getBalance().getCurrency() + " " + getAmount());//交易金额
        receiptText.append("\n" +
                "\u4ea4\u6613\u7c7b\u578b:" + transType);//交易类型
        receiptText.append("\n" +
                "\u624b\u7eed\u8d39:");//手续费
        receiptText.append("\n" +
                "\u8f6c\u5165\u8d26\u53f7:");//转入账号
        receiptText.append("\n" +
                "\u6d41\u6c34\u53f7:");//流水号
        receiptText.append("\n" +
                "\u5e94\u7b54\u7801:");//应答码
        receiptText.append("\n" +
                "\u5907\u6ce8:");//备注
        return receiptText.toString();
    }

    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    public String getCurBalance() {
        return curBalance;
    }

    public String getTransType() {
        return transType;
    }

    public void setTransType(String transType) {
        this.transType = transType;
    }

    public String getDateTime() {
        return dateTime;
    }

    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public abstract void updateAmount(String amount);
}
